﻿<?php
@session_start();
require_once("../includes/public.inc.php");
$s = isset($_GET['s'])?$_GET['s']:'';
$act = isset($_GET['act'])?$_GET['act']:'';//也是type
$openid = isset($_GET['openid'])?$_GET['openid']:'';//echo $openid;exit;
if ($act=='dg')
{
	$user = isset($_POST['user'])?$_POST['user']:'';//手机号
	$username = isset($_POST['userName'])?$_POST['userName']:'';//真实姓名
	$sex = '';
	$tel = isset($_POST['tel'])?$_POST['tel']:'';//店铺固定电话
	$area = isset($_POST['area'])?$_POST['area']:'';//店铺固定电话
	$password = isset($_POST['password'])?$_POST['password']:'';
	$password2 = isset($_POST['password2'])?$_POST['password2']:'';
	$shopname = isset($_POST['shopname'])? $_POST['shopname']:'';
	$address = '';
	$wx = isset($_POST['wx'])?$_POST['wx']:'';
	$province = isset($_POST['province'])?$_POST['province']:'';
	$city = isset($_POST['city'])?$_POST['city']:'';
	$tel_area = $area.'-'.$tel;
}
else 
{
	echo "<script>alert('注册失败!入口不正确');history.go(-1);</script>";exit;
}
if ($user&&$username&&$password&&$wx&&$tel&&$area)
{
	//echo "select * from " .DBQIAN. "daogou where username='".trim($user)."' or openid='".$openid."'";exit;
	$select_dg = mysql_fetch_array(mysql_query("select * from " .DBQIAN. "daogou where username='".trim($user)."' or wx_openid='".$openid."'"));
	if ($select_dg)
	{
		echo "<script>alert('注册失败!你已经注册，请直接登录.需要找回密码，请联系管理员!');history.go(-1);</script>";exit;
	}
	if ($act == 'dg')
	{
		$add = mysql_query("insert into ".DBQIAN."daogou(username,name,password,shopname,province,city,shopaddress,last_login,create_time,wx_user,wx_openid,status,sex,tel) values('".$user."','".$username."','".$password."','".$shopname."','".$province."','".$city."','".$address."','".time()."','".date('Y-m-d H:i:s',time())."','".$wx."','".$openid."',1,'".$sex."','".$tel_area."')");
		$add_id = mysql_insert_id();//echo $add_id;exit;
		if ($add&&$add_id)
		{
			$exsit_user = mysql_fetch_array(mysql_query("select * from ".DBQIAN."daogou where id=".$add_id." order by id desc limit 1"));
			if ($exsit_user)
			{
				$_SESSION['username'] = $exsit_user['username'];
				$_SESSION['password'] = $exsit_user['password'];
				header("Location: zhengp.php?s=".trim($s)."&openid=".$openid);exit;//注册成功后直接跳到审核页面
			}
			else 
			{
				header("Location: login.php?s=".$s."&openid=".$openid);exit;//注册失败跳到登录页面
			}
		}
		else 
		{
			echo "<script>alert('注册失败!');history.go(-1);</script>";exit;
		}
	}
}
else 
{
	echo "<script>alert('请正确并完整填写你的信息!');history.go(-1);</script>";exit;
}